home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 1833 / 1833.xpi / chrome / yoono.jar / content / yoono / panelOverlay.js < prev    next >
Text File  |  2009-12-16  |  6KB  |  135 lines

  1. Components.utils.import("resource://yoono/yoonoService.js");
  2. Components.utils.import("resource://yoono/yoonoBkmSync.js");
  3. Components.utils.import("resource://yoono/yoonoLog.js");
  4. const YNPREFBRANCH = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("extensions.yoono.");
  5. Components.utils.import("resource://yoono/yoonoDialogs.js");
  6.  
  7. var gStrbundle;
  8. var serverUrl;
  9. var bmView = null;
  10. var privateMarker = 'yoonoPrivate';
  11.  
  12. function log(m) {
  13.   var console = Components.classes["@mozilla.org/consoleservice;1"].getService(Components.interfaces.nsIConsoleService);
  14.   console.logStringMessage(m);
  15. }
  16.  
  17. function init() {
  18. try {
  19. log('init');
  20.     var ua = navigator.userAgent.toLowerCase();
  21.     if(ua.indexOf('mac os')!=-1) {
  22.       privateMarker = 'yoonoMacPrivate';
  23.     }
  24.    bmView = document.getElementById("bookmarks-view")||null;
  25.    gStrbundle=document.getElementById("yoono-strings");
  26.    serverUrl = YOONO_PREFS.get('serverurl');
  27.    createYoonoCustomView();
  28.    attachYoonoBkmMenu('sidebar');
  29.    log('ok!');
  30. } catch(e) {
  31.   log(e);
  32. }
  33. }
  34.  
  35. function createYoonoCustomView() {
  36.  
  37.     var view = {
  38.         oldView: {},
  39.  
  40.         /* nsISupports */
  41.         QueryInterface: function (aIID) {
  42.             if (Components.interfaces.nsITreeView.equals(aIID) || 
  43.                 Components.interfaces.nsIClassInfo.equals(aIID) ||
  44.                 Components.interfaces.nsISupportsWeakReference.equals(aIID) ||
  45.                 Components.interfaces.nsISupports.equals(aIID))
  46.                   return this;
  47.               throw Components.results.NS_NOINTERFACE;  
  48.             },
  49.         /* nsIClassInfo */ 
  50.         getInterfaces: function getInterfaces(count) {
  51.         count.value = 4;
  52.         return [Components.interfaces.nsITreeView,
  53.               Components.interfaces.nsIClassInfo,
  54.               Components.interfaces.nsISupportsWeakReference,
  55.               Components.interfaces.nsISupports];
  56.         },
  57.  
  58.         getHelperForLanguage: function getHelperForLanguage(language) { return null; }, 
  59.  
  60.         get contractID() { return null; },
  61.         get classDescription() { return "yonooTreeView"; },
  62.         get classID() { return null; },
  63.         get implementationLanguage() { return
  64.         Components.interfaces.nsIProgrammimgLanguage.JAVASCRIPT; },
  65.         get flags() { return
  66.         Components.interfaces.nsIClassInfo.MAIN_THREAD_ONLY |
  67.         Components.interfaces.nsIClassInfo.DOM_OBJECT; },
  68.  
  69.         /* nsITreeView methods go here */ 
  70.  
  71.         get rowCount() { return this.oldView.rowCount },
  72.  
  73.         canDrop: function(index, orientation) { return this.oldView.canDrop(index, orientation); },
  74.         cycleCell: function (row, col) {this.oldView.cycleCell(row, col);},
  75.         cycleHeader: function (col) {this.oldView.cycleHeader(col);},
  76.         drop: function (row, orientation) {this.oldView.drop(row ,orientation);},
  77.  
  78.         getCellProperties: function (index, column, prop) {
  79.            if (null == bmView) 
  80.               bmView = document.getElementById("bookmarks-view");
  81.            this.oldView.getCellProperties(index,column,prop);
  82.            var resource = bmView.tree.builder.getResourceAtIndex(index);
  83.            if (YOONO_BKM.isPrivate(resource.Value)) {
  84.               var aserv=Components.classes["@mozilla.org/atom-service;1"].getService(Components.interfaces.nsIAtomService);
  85.               prop.AppendElement(aserv.getAtom(privateMarker));
  86.           }
  87.         },
  88.  
  89.         getCellText: function(row, col) {return this.oldView.getCellText(row, col);},
  90.         getCellValue: function(row, col) {return this.oldView.getCellValue(row, col);},
  91.         getColumnProperties: function(col, properties) {this.oldView.getColumnProperties(col, properties);},
  92.         getImageSrc: function(row, col) {return this.oldView.getImageSrc(row, col);}, //
  93.         getLevel: function(index) {return this.oldView.getLevel(index);}, //
  94.         getParentIndex: function(rowIndex) {return this.oldView.getParentIndex(rowIndex);}, //
  95.         getProgressMode: function(row , col) {return this.oldView.getProgressMode(row , col);},
  96.         getRowProperties: function(index, properties) {this.oldView.getRowProperties(index , properties);}, //
  97.         hasNextSibling: function(rowIndex, afterIndex) {return this.oldView.hasNextSibling(rowIndex, afterIndex);},
  98.         isContainer: function(index) {return this.oldView.isContainer(index);}, //
  99.         isContainerEmpty: function(index) {return this.oldView.isContainerEmpty(index);},
  100.         isContainerOpen: function(index) {return this.oldView.isContainerOpen(index);},
  101.         isEditable: function(row, col) {return this.oldView.isEditable(row, col);},
  102.         isSeparator: function(index) {return this.oldView.isSeparator(index);}, //
  103.         isSorted: function() {return this.oldView.isSorted();},
  104.         performAction: function(action) {this.oldView.performAction(action);},
  105.         performActionOnCell: function(action, row, col) {this.oldView.performActionOnCell(action, row, col);},
  106.         performActionOnRow: function(action, row) {this.oldView.performActionOnRow(action, row);},
  107.         selectionChanged: function() {this.oldView.selectionChanged();},
  108.         setCellText: function(row, col, value) {this.oldView.selectionChanged(row, col, value);},
  109.         setCellValue: function(row , col , value) {this.oldView.setCellValue(row, col, value);},
  110.         setTree: function(tree) {this.oldView.setTree(tree);},
  111.         toggleOpenState: function(index){this.oldView.toggleOpenState(index);}
  112.     }; 
  113.     
  114.     var mytree = bmView.tree;
  115.     view.oldView = mytree.view;
  116.     mytree.view = view;
  117.    
  118.     
  119. }
  120.  
  121. function selectedBkm() {
  122.     if (PlacesUtils) { // FF3
  123.         var view = document.getElementById("bookmarks-view");
  124.         return view.selectedNode.itemId;
  125.     } else { // FF2
  126.         var tree = bmView.tree;
  127.         var selection = tree.view.selection;
  128.         var currentIndex=selection.currentIndex;
  129.         var resource = tree.builder.getResourceAtIndex(currentIndex);
  130.         return resource.Value;
  131.     }
  132. }
  133.  
  134. window.addEventListener("load", function() { init(); }, false);
  135.